package com.hlkj.util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSourceFactory;

public final class JDBCUtil {
	private static DataSource myDataSource = null;

	private JDBCUtil() {

	}

	static {
		try {
			Properties pro = new Properties();
			InputStream is = JDBCUtil.class.getClassLoader()
					.getResourceAsStream("jdbc.properties");
			pro.load(is);
			myDataSource = BasicDataSourceFactory.createDataSource(pro);
		} catch (Exception e) {

		}
	}

	/**
	 * 获取连接
	 * @return Connection
	 * @throws SQLException
	 */
	public static Connection getConnection() throws SQLException {
		System.out.println("====新建立了一次连接====");
		return myDataSource.getConnection();
	}
}
